package com.techfork.hutool.teck;

import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.lang.Singleton;

public class TestThreads {
    private static TestThreads instance;
    private static TestThreads build() {
        if(instance != null) {
            return instance;
        }
        return instance = new TestThreads();
    }

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch downLatch = new CountDownLatch(100);
        Set<TestThreads> set = new ConcurrentHashSet<>();
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                downLatch.countDown();
                TestThreads testThreads = Singleton.get(TestThreads.class);
                testThreads = TestThreads.build();
//                testThreads = new TestThreads();
                set.add(new TestThreads());
            }).start();
        }
        TimeUnit.SECONDS.sleep(3);
        System.out.println(set.size());
    }


}
